#include <fstream>
#include <iostream>
#include <string.h>
#include <sstream>
#include <vector>

struct Data {
    int lhs;
    int rhs;
};


void get_data(const std::string& file, std::vector<Data>& data) {
    std::ifstream fin(file, std::ios::in);

    if (!fin.is_open()) {
        std::cerr << "File open error!" << std::endl;
        return;
    }

    std::string line;
    while (std::getline(fin, line)) {
        Data item;
        std::istringstream iss(line);
        int val;
        iss >> val; item.lhs = val;
        iss >> val; item.rhs = val;

        data.push_back(item);
    }
    fin.close();
}


void write_data(const std::string& file, std::vector<Data>& data) {
    std::ofstream fout(file, std::ios::out);
    if (!fout.is_open()) {
        std::cerr << "File Open Error!" << std::endl;
        return;
    }

    std::string line;
    for (auto& item : data) {
        line = std::to_string(item.lhs) + " " + std::to_string(item.rhs) + "\n";
        fout << line;
    }

    fout.close();
    return;
}


int main() {
    std::string file = "./barrack/barrack1.in";
    std::vector<Data> data;

    get_data(file, data);

    // for (auto& item : data)
    //     printf("%d  %d\n", item.lhs, item.rhs);
    write_data("./tmp.txt", data);

    return 0;
}